package com.bugman.managed;

import java.io.IOException;

/**
 *
 * @author Ediczech
 */
public class LoginBean extends BaseBean {

    private String username;
    private String userRole;

    public void logout() {
        String name = getUsername();
        getSession().invalidate();
        try {
            redirect("index.jsp");
            logger.info("Uživatel: " + name + " úspěšně odhlášen.");
        } catch (IOException ex) {
            logger.error(ex);
        }
    }

    public String getUsername() {
        return getLoggedUserName();
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUserRole() {
        String result = "Unknown";
        if(isUserInRole("Admin")) {
            result = "Admin";
        }
        else if (isUserInRole("Developer")) {
            result = "Developer";
        }
        else if (isUserInRole("User")) {
            result = "User";
        }
        return result;
    }
    
    public void setUserRole(String userRole) {
        this.userRole = userRole;
    }

}